package ide.ccf.ccproject;

import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.jface.viewers.ViewerFilter;

/**
 * 生成文件筛选器
 *
 */
public class GeneratedFilesFilter extends ViewerFilter 
{
	/**
	 * 某些生成的文件不显示在项目管理器中
	 */
	public boolean select(Viewer viewer, Object parentElement, Object element) 
	{
		IResource resource = null;
		
		if (element instanceof IResource)
			resource = (IResource)element;
		else if (element instanceof IAdaptable)
			resource = (IResource)((IAdaptable)element).getAdapter(IResource.class);
		
		if (resource != null) 
		{
			if (resource.getName().startsWith("moc_") && resource.getName().endsWith(".cpp"))
				return false;
			
			if (resource.getName().startsWith("ui_") && resource.getName().endsWith(".h"))
				return false;
			
			if (resource.getName().startsWith("qrc_") && resource.getName().endsWith(".cpp"))
				return false;
		}
		return true;
	}
}